/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine - graphics/renderer
// Copyright (c) 2015.  All Rights Reserved
//
// File:		AESimpleRenderState.h
// Author:		Gianluca Belardelli
// Date:		10/02/2015
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AESIMPLERENDERSTATE_INL_
#define _AESIMPLERENDERSTATE_INL_


AE_FORCEINLINE AESimpleRenderState::AESimpleRenderState( void )
{
	nAllProperties = 0;
	nRenderFlags = AERENDERSTATEFLAG_FRONTFACE | AERENDERSTATEFLAG_FILTERING | AERENDERSTATEFLAG_USEADDITIVEALPHA;
}

AE_FORCEINLINE AESimpleRenderState::AESimpleRenderState( AEINT32 nTransp, AEINT32 nFlags )
{
	nAllProperties = 0;
	nTranspMode = nTransp;
	nRenderFlags = nFlags;
}

AE_FORCEINLINE void AESimpleRenderState::Invalidate( void )
{
	nAllProperties = -1;
}

AE_FORCEINLINE void AESimpleRenderState::SetTransparency( AEINT32 nTransp )
{
	nTranspMode=nTransp;
}

AE_FORCEINLINE AEINT32 AESimpleRenderState::GetTransparency( void ) const
{
	return nTranspMode;
}

AE_FORCEINLINE void AESimpleRenderState::SetFaceCullMode( AECullMode nMode )
{
	SetFlag( AERENDERSTATEFLAG_DOUBLESIDED );
	
	if( nMode == AECULL_FRONT )
		RemoveFlag( AERENDERSTATEFLAG_FRONTFACE );
	
	if( nMode == AECULL_BACK )
		RemoveFlag( AERENDERSTATEFLAG_BACKFACE );
}

AE_FORCEINLINE AECullMode AESimpleRenderState::GetFaceCullMode( void ) const
{
	if( !IsFlagSet( AERENDERSTATEFLAG_FRONTFACE) )
		return AECULL_FRONT;
		
	if( !IsFlagSet( AERENDERSTATEFLAG_BACKFACE ) )
		return AECULL_BACK;
		
	return AECULL_NONE;
}

AE_FORCEINLINE void AESimpleRenderState::SetFlags( AEINT32 nMask )
{
	nRenderFlags = nMask;
}

AE_FORCEINLINE void AESimpleRenderState::SetFlag( AEINT32 nMask )
{
	nRenderFlags |= nMask;
}

AE_FORCEINLINE void AESimpleRenderState::RemoveFlag( AEINT32 nMask )
{
	nRenderFlags &= ( ~nMask );
}

AE_FORCEINLINE AEINT32 AESimpleRenderState::GetFlags( void ) const
{
	return nRenderFlags;
}

AE_FORCEINLINE AEBOOL32 AESimpleRenderState::IsFlagSet( AEINT32 nMask ) const
{
	return ( nRenderFlags & nMask ) == nMask;
}

AE_FORCEINLINE operator AEINT32 &AESimpleRenderState::()
{
	return nAllProperties;
}

AE_FORCEINLINE AEINT32 &AESimpleRenderState::operator = ( AEINT32 nOther )
{
	nAllProperties = nOther;
	return nAllProperties;
}

AE_FORCEINLINE AEINT32 &AESimpleRenderState::operator = ( const AESimpleRenderState &refOther )
{
	nAllProperties = refOther.nAllProperties;
	return nAllProperties;
}

AE_FORCEINLINE AEBOOL32 AESimpleRenderState::operator == ( const AESimpleRenderState &refOther ) const
{
	return nAllProperties == refOther.nAllProperties;
}

AE_FORCEINLINE AEBOOL32 AESimpleRenderState::operator != ( const AESimpleRenderState &refOther ) const
{
	return nAllProperties != refOther.nAllProperties;
}

#endif // _AESIMPLERENDERSTATE_INL_
